file is not upload using retrofit in kotlin

269

define ('SITE_ROOT', realpath(dirname(__FILE__)));
//if(isset($_FILES['upload_file'])) {

    $target_dir = "/uploads/";
    $target_file = $target_dir . microtime().rand(99999,999999).basename($_FILES["upload_file"]["name"]);
    $uploadOk = 1;
    $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
    if(isset($_POST["submit"])) {
        $check = getimagesize($_FILES["upload_file"]["tmp_name"]);
        if($check !== false) {
            $uploadOk = 1;
        } else {
            echo '{"status":"error","message":"فایل معتبر نیست"}';
            $uploadOk = 0;
        }
    }


// Check file size
    if ($_FILES["upload_file"]["size"] > 500000) {
        echo '{"status":"error","message":"حجم عکس نباید بیشتر از 500 کیلوبایت باشد"}';
        $uploadOk = 0;
    }
// Allow certain file formats
    if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
         ) {
        echo '{"status":"error","message":"فرمت عکس اشتباه است"}';
        $uploadOk = 0;
    }
// Check if $uploadOk is set to 0 by an error
    if ($uploadOk == 0) {
        echo '{"status":"error","message":"متاسفانه عکس آپلود نشد"}';
// if everything is ok, try to upload file
    } else {
        if (move_uploaded_file($_FILES["upload_file"]["tmp_name"], SITE_ROOT.$target_file)) {
            echo '{"status":"success","message":"عکس با موفقیت آپلود شد"}';
        } else {
            echo '{"status":"error","message":"مشکل در آپلود فایل"}';
        }
    //}
}

Comments

Submit
0 Comments

More Questions

kotlin date to stringtoast in kotlin zsh: command not found: adb
coroutines kotlin android dependency2d array in kotlin how to initialize mutable list kotlin
date format kotlinkotlin check if string contains android recyclerview scroll to bottom
on click in kotlinrandom string generator kotlin kotlin list add
kotlin onclicklistenerkotlin empty list kotlin filter not null
what is the difference between const and valkotlin print list text is behind BottomNavigationView
kotlinx coroutines dependencyhow to check internet connection in android programmatically kotlin recyclerview onclicklistener kotlin
kotlin check if edittext is emptycountdowntimer kotlin kotlin null safety
how to get date in kotlinkotlin repeat n times split string kotlin
Kotlin redundant FindViewByIdfile is not upload using retrofit in kotlin how to uppercase the first letter of a string in kotlin
how to make dialog transparent androidstartactivityforresult deprecated android kotlin remove name from an activity
button inside a recycle view in android in kotlindate to string kotlin while loop kotlin
kotlin variable possiblement nullregex find emails kotlin for decrement
kotlin filter map by keyadd kotlin parcelize plugin in new android studio list map by index and value kotlin
object vs companion object kotlinhow to get resource how to get data in mainActivity from a parcelable data class in kotlin
android navigation drawer not navigating with navcontrollerdrawable to bitmap android kotlin double tab exit button